Skip to content

Python: fix alerts for py/import-deprecated-module#2711

Merged
tausbn merged 5 commits intogithub:masterfrom
RasmusWL:python-fix-import-deprecated-module
Feb 17, 2020
Merged

Python: fix alerts for py/import-deprecated-module#2711
tausbn merged 5 commits intogithub:masterfrom
RasmusWL:python-fix-import-deprecated-module

Conversation

@RasmusWL
Copy link
Copy Markdown
Member

The old query had

from ImportExpr imp, Stmt s, Expr e
where
    s.getASubExpression() = e and
    (e = imp or e.contains(imp))
select s, ...

and before merging this, I would like to understand if there are any meaningful results that this would catch, compared to

from ImportExpr imp, Stmt s
where
    s.getASubExpression() = imp
select s, ...

Clearly, the old code had some nasty side-effects since it would alert on multiple levels, as in https://lgtm.com/projects/g/h2oai/h2o-3/snapshot/c78f48eea306360d9044197c83a24bacb813b839/files/py2/h2o_objects.py?sort=name&dir=ASC&mode=heatmap#x3ea6a547ca4855b1:1 but I'm wondering if there is any desirable results that are not found by the second variation.

This changes the location from the import statement, to the actual expression
$ python2 -W default -c 'import posixfile'
-c:1: DeprecationWarning: The posixfile module is deprecated; fcntl.lockf() provides better locking

https://docs.python.org/2.7/library/posixfile.html
@RasmusWL
Copy link
Copy Markdown
Member Author

from ImportExpr imp, Stmt s, Expr e
where
    s.getASubExpression() = e and
    not e = imp and
    e.contains(imp) and
    imp.getScope() = s.getScope()
select s, e, imp

gives the result from md5 import md5 -- so the e.contains part makes sense if you need to select a statement. I just changed the query to select a ImportExpr, so no problem 👍 🚀

@RasmusWL RasmusWL marked this pull request as ready for review January 29, 2020 11:01
@RasmusWL RasmusWL requested a review from a team as a code owner January 29, 2020 11:01
@tausbn tausbn self-assigned this Feb 12, 2020
Copy link
Copy Markdown
Contributor

@tausbn tausbn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. 👍

@tausbn tausbn merged commit 03ae783 into github:master Feb 17, 2020
@RasmusWL RasmusWL deleted the python-fix-import-deprecated-module branch February 17, 2020 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants